package com.hmsm.sys.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public abstract class LocalUser<D extends LocalDept<D, U>, U extends LocalUser<D, U, R>, R extends LocalRole> {

	private RTXUserBean bindUser;
    
	public RTXUserBean getBindUser() {
		return bindUser;
	}

	public void setBindUser(RTXUserBean bindUser) {
		this.bindUser = bindUser;
	}
	
	public abstract boolean isSuperAdmin();
	
	public abstract boolean isSysAdmin();

	public abstract D getDepart();

	public abstract String getUserName();

	public abstract String getName();

	public abstract String getTelPhone();

	public abstract String getEmail();

	public abstract String getIdType();

	public abstract Integer getPkId();

	public abstract void setUserName(String userName);

	public abstract void setName(String name);

	public abstract void setIdType(String stringValue);

	public abstract void setTelPhone(String stringValue);

	public abstract void setEmail(String stringValue);

	public abstract void setDepart(D bindDept);

	public abstract void resetPassword();

	/**
	 * 是否直属于指定部门
	 * @param depart
	 * @return
	 */
	public abstract boolean affiliatedWithDepart(D depart);
	
	public abstract List<? extends R> getRoles();
	
	public abstract void setRoles(List<R> roles);

	public abstract List<D> getUserDepts();

	public abstract void setUserDepts(List<D> userDepts);

	public void addUserDept(D userDept) {
		if (getUserDepts()==null){
			setUserDepts(new ArrayList<D>());
		}
		if(userDept!=null){
			boolean have = false;
			for(D dept:getUserDepts()){
				if(userDept!=null&&dept.getPkId().equals(userDept.getPkId())){
					have = true;
					break;
				}
			}
			if(!have){
				getUserDepts().add(userDept);
			}
		}
	}

	public void removeUserDept(D userDept) {
		if (getUserDepts()==null){
			setUserDepts(new ArrayList<D>());
		}
		for(D dept:getUserDepts()){
			if (dept==userDept||dept.equals(userDept)||dept.getPkId().equals(userDept.getPkId())){
				getUserDepts().remove(dept);
				break;
			}
		}
	}

}
